package driverSelf;
import java.io.File;
import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerDriverService;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class IEDriver {
    public WebDriver driver=null;
    public InternetExplorerDriverService service=null;
    public IEDriver(String driverpath){
        System.setProperty("webdriver.ie.driver",driverpath);
        DesiredCapabilities ieCapabilities=new DesiredCapabilities();
        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
        ieCapabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING,true);
        InternetExplorerOptions ieOptions=new InternetExplorerOptions(ieCapabilities);
        try{
            service=new InternetExplorerDriverService.Builder().usingDriverExecutable(new File(driverpath)).usingAnyFreePort().build();
            service.start();
        } catch (IOException e){
            e.printStackTrace();
        }
        try {
            this.driver=new InternetExplorerDriver(service,ieOptions);
            driver.get("about:blank");
        } catch (Exception e){
            e.printStackTrace();
            System.out.println("创建IE driver失败！！");
        }
    }
    public WebDriver getDriver(){
        return driver;
    }
    public void closeIE(){
        driver.quit();
        service.stop();
    }
}
